{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b9267302-d736-48dc-a752-4ecb2dd3d654",
   "metadata": {},
   "source": [
    "# pandas基础"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c590ef92-5fe7-4a94-a08c-11de84b578cb",
   "metadata": {},
   "source": [
    "df：任意的Pandas DataFrame对象\n",
    "\n",
    "s：任意的Pandas Series对象"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aa3b18f6-9e19-40f0-9e7e-dfdbeb4c0680",
   "metadata": {},
   "source": [
    "> 请注意，xlwt库只支持旧版Excel文件（.xls格式），因此不能直接保存为新版Excel文件（.xlsx格式）。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "56453e94-d734-4a44-866c-267c3e18114d",
   "metadata": {},
   "source": [
    "```python\n",
    "# 读入文件\n",
    "\n",
    "filename = \"\"\n",
    "url=\"\"\n",
    "json_string = \"\"\n",
    "pd.read_csv(filename); \t\t\t\t\t\t # 从CSV文件导入数据\n",
    "pd.read_table(filename); \t\t\t\t\t # 从限定分隔符的文本文件导入数据\n",
    "pd.read_excel(filename); \t\t\t\t\t # 从Excel文件导入数据\n",
    "pd.read_sql(query, connection_object);\t\t  # 从SQL表/库导入数据\n",
    "pd.read_json(json_string); \t\t\t\t\t # 从JSON格式的字符串导入数据\n",
    "pd.read_html(url); \t\t\t\t\t\t\t# 解析URL、字符串或者HTML文件，抽取其中的tables表格\n",
    "pd.read_clipboard(); \t\t\t\t\t\t# 从你的粘贴板获取内容，并传给read_table()\n",
    "pd.DataFrame(dict); \t\t\t\t\t\t# 从字典对象导入数据，Key是列名，Value是数据\n",
    "# ...\n",
    "\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6b9b8930-e6a6-4681-8fc3-ef87676b8587",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "9cffd2f7-8c16-4855-8acb-a792524db4d9",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt    # "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "a1cb36eb-a63d-465d-9d9e-c3158c049422",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2.1.4'"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.__version__"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "4b3d190e-084a-4448-b79b-530cc5989b43",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Key Developments By Date</th>\n",
       "      <th>Key Developments by Type</th>\n",
       "      <th>Company Name(s)</th>\n",
       "      <th>Key Development Headline</th>\n",
       "      <th>Key Development Situation</th>\n",
       "      <th>Key Development Sources</th>\n",
       "      <th>Geographic Locations</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2023-12-29</td>\n",
       "      <td>Business Expansions</td>\n",
       "      <td>Ascend Wellness Holdings, Inc. (CNSX:AAWH.U)</td>\n",
       "      <td>Ascend Wellness Holdings, Inc. Announces Openi...</td>\n",
       "      <td>Ascend Wellness Holdings, Inc. announced the o...</td>\n",
       "      <td>SEDAR</td>\n",
       "      <td>United States and Canada (Primary)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2023-12-29</td>\n",
       "      <td>Business Expansions</td>\n",
       "      <td>Generation Gold Corp. (TSXV:GEN)</td>\n",
       "      <td>Generation Gold Announces Closing of YATH Prop...</td>\n",
       "      <td>Generation Gold Corp. completed its acquisitio...</td>\n",
       "      <td>SEDAR</td>\n",
       "      <td>United States and Canada (Primary)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2023-12-28</td>\n",
       "      <td>Business Expansions</td>\n",
       "      <td>Ophir Gold Corp. (TSXV:OPHR)</td>\n",
       "      <td>Ophir Gold Corp. Receives Approval to Option t...</td>\n",
       "      <td>Ophir Gold Corp. announced that further to its...</td>\n",
       "      <td>SEDAR</td>\n",
       "      <td>United States and Canada (Primary)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2023-12-28</td>\n",
       "      <td>Business Expansions</td>\n",
       "      <td>HIVE Digital Technologies Ltd. (TSXV:HIVE)</td>\n",
       "      <td>HIVE Digital Technologies Ltd. Expands Its AI ...</td>\n",
       "      <td>HIVE Digital Technologies Ltd. announces the p...</td>\n",
       "      <td>SEC Form 6k</td>\n",
       "      <td>United States and Canada (Primary)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2023-12-28</td>\n",
       "      <td>Business Expansions</td>\n",
       "      <td>Capital Power Corporation (TSX:CPX)</td>\n",
       "      <td>Capital Power Completes Acquisition of 50.15% ...</td>\n",
       "      <td>Capital Power Corporation successfully complet...</td>\n",
       "      <td>SEDAR</td>\n",
       "      <td>United States and Canada (Primary)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9995</th>\n",
       "      <td>2021-03-22</td>\n",
       "      <td>Business Expansions</td>\n",
       "      <td>DMG Blockchain Solutions Inc. (TSXV:DMGI)</td>\n",
       "      <td>DMG Blockchain Solutions Purchases 2,915 ASIC ...</td>\n",
       "      <td>DMG Blockchain Solutions Inc. announced the pu...</td>\n",
       "      <td>GlobeNewswire</td>\n",
       "      <td>United States and Canada (Primary)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9996</th>\n",
       "      <td>2021-03-22</td>\n",
       "      <td>Business Expansions</td>\n",
       "      <td>Eastman Chemical Company (NYSE:EMN)</td>\n",
       "      <td>Eastman Announces Investment to Upgrade and Ex...</td>\n",
       "      <td>Eastman Chemical Company announced it is makin...</td>\n",
       "      <td>Business Wire</td>\n",
       "      <td>United States and Canada (Primary)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9997</th>\n",
       "      <td>2021-03-22</td>\n",
       "      <td>Business Expansions</td>\n",
       "      <td>GrowGeneration Corp. (NasdaqCM:GRWG)</td>\n",
       "      <td>GrowGeneration Acquires Agron.io B2b Integrate...</td>\n",
       "      <td>GrowGeneration Corp. announced its acquisition...</td>\n",
       "      <td>PR Newswire</td>\n",
       "      <td>United States and Canada (Primary)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9998</th>\n",
       "      <td>2021-03-22</td>\n",
       "      <td>Business Expansions</td>\n",
       "      <td>Universal Technical Institute, Inc. (NYSE:UTI)</td>\n",
       "      <td>Universal Technical Institute to Open a New Ca...</td>\n",
       "      <td>Universal Technical Institute Inc. plans to ex...</td>\n",
       "      <td>PR Newswire</td>\n",
       "      <td>United States and Canada (Primary)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9999</th>\n",
       "      <td>2021-03-22</td>\n",
       "      <td>Business Expansions</td>\n",
       "      <td>Trex Company, Inc. (NYSE:TREX)</td>\n",
       "      <td>Trex Company Announces Capacity Expansion Update</td>\n",
       "      <td>Trex Company, Inc. announced that in addition ...</td>\n",
       "      <td>Business Wire</td>\n",
       "      <td>United States and Canada (Primary)</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>10000 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     Key Developments By Date Key Developments by Type  \\\n",
       "0                  2023-12-29      Business Expansions   \n",
       "1                  2023-12-29      Business Expansions   \n",
       "2                  2023-12-28      Business Expansions   \n",
       "3                  2023-12-28      Business Expansions   \n",
       "4                  2023-12-28      Business Expansions   \n",
       "...                       ...                      ...   \n",
       "9995               2021-03-22      Business Expansions   \n",
       "9996               2021-03-22      Business Expansions   \n",
       "9997               2021-03-22      Business Expansions   \n",
       "9998               2021-03-22      Business Expansions   \n",
       "9999               2021-03-22      Business Expansions   \n",
       "\n",
       "                                     Company Name(s)  \\\n",
       "0       Ascend Wellness Holdings, Inc. (CNSX:AAWH.U)   \n",
       "1                   Generation Gold Corp. (TSXV:GEN)   \n",
       "2                       Ophir Gold Corp. (TSXV:OPHR)   \n",
       "3         HIVE Digital Technologies Ltd. (TSXV:HIVE)   \n",
       "4                Capital Power Corporation (TSX:CPX)   \n",
       "...                                              ...   \n",
       "9995       DMG Blockchain Solutions Inc. (TSXV:DMGI)   \n",
       "9996             Eastman Chemical Company (NYSE:EMN)   \n",
       "9997            GrowGeneration Corp. (NasdaqCM:GRWG)   \n",
       "9998  Universal Technical Institute, Inc. (NYSE:UTI)   \n",
       "9999                  Trex Company, Inc. (NYSE:TREX)   \n",
       "\n",
       "                               Key Development Headline  \\\n",
       "0     Ascend Wellness Holdings, Inc. Announces Openi...   \n",
       "1     Generation Gold Announces Closing of YATH Prop...   \n",
       "2     Ophir Gold Corp. Receives Approval to Option t...   \n",
       "3     HIVE Digital Technologies Ltd. Expands Its AI ...   \n",
       "4     Capital Power Completes Acquisition of 50.15% ...   \n",
       "...                                                 ...   \n",
       "9995  DMG Blockchain Solutions Purchases 2,915 ASIC ...   \n",
       "9996  Eastman Announces Investment to Upgrade and Ex...   \n",
       "9997  GrowGeneration Acquires Agron.io B2b Integrate...   \n",
       "9998  Universal Technical Institute to Open a New Ca...   \n",
       "9999   Trex Company Announces Capacity Expansion Update   \n",
       "\n",
       "                              Key Development Situation  \\\n",
       "0     Ascend Wellness Holdings, Inc. announced the o...   \n",
       "1     Generation Gold Corp. completed its acquisitio...   \n",
       "2     Ophir Gold Corp. announced that further to its...   \n",
       "3     HIVE Digital Technologies Ltd. announces the p...   \n",
       "4     Capital Power Corporation successfully complet...   \n",
       "...                                                 ...   \n",
       "9995  DMG Blockchain Solutions Inc. announced the pu...   \n",
       "9996  Eastman Chemical Company announced it is makin...   \n",
       "9997  GrowGeneration Corp. announced its acquisition...   \n",
       "9998  Universal Technical Institute Inc. plans to ex...   \n",
       "9999  Trex Company, Inc. announced that in addition ...   \n",
       "\n",
       "     Key Development Sources                Geographic Locations  \n",
       "0                      SEDAR  United States and Canada (Primary)  \n",
       "1                      SEDAR  United States and Canada (Primary)  \n",
       "2                      SEDAR  United States and Canada (Primary)  \n",
       "3                SEC Form 6k  United States and Canada (Primary)  \n",
       "4                      SEDAR  United States and Canada (Primary)  \n",
       "...                      ...                                 ...  \n",
       "9995           GlobeNewswire  United States and Canada (Primary)  \n",
       "9996           Business Wire  United States and Canada (Primary)  \n",
       "9997             PR Newswire  United States and Canada (Primary)  \n",
       "9998             PR Newswire  United States and Canada (Primary)  \n",
       "9999           Business Wire  United States and Canada (Primary)  \n",
       "\n",
       "[10000 rows x 7 columns]"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_excel(r\"data/KeyDevelopment Screening Report.xls\",header=7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "05f0137d-39c1-4fa6-bbd3-13f8f7736c87",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting xlrd\n",
      "  Downloading xlrd-2.0.1-py2.py3-none-any.whl (96 kB)\n",
      "     ---------------------------------------- 0.0/96.5 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/96.5 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/96.5 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/96.5 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/96.5 kB ? eta -:--:--\n",
      "     ---- ----------------------------------- 10.2/96.5 kB ? eta -:--:--\n",
      "     ---- ----------------------------------- 10.2/96.5 kB ? eta -:--:--\n",
      "     ---- ----------------------------------- 10.2/96.5 kB ? eta -:--:--\n",
      "     ---- ----------------------------------- 10.2/96.5 kB ? eta -:--:--\n",
      "     ---- ----------------------------------- 10.2/96.5 kB ? eta -:--:--\n",
      "     -------------------------------- ----- 81.9/96.5 kB 270.5 kB/s eta 0:00:01\n",
      "     -------------------------------- ----- 81.9/96.5 kB 270.5 kB/s eta 0:00:01\n",
      "     -------------------------------- ----- 81.9/96.5 kB 270.5 kB/s eta 0:00:01\n",
      "     -------------------------------- ----- 81.9/96.5 kB 270.5 kB/s eta 0:00:01\n",
      "     -------------------------------- ----- 81.9/96.5 kB 270.5 kB/s eta 0:00:01\n",
      "     -------------------------------- ----- 81.9/96.5 kB 270.5 kB/s eta 0:00:01\n",
      "     -------------------------------------- 96.5/96.5 kB 162.5 kB/s eta 0:00:00\n",
      "Installing collected packages: xlrd\n",
      "Successfully installed xlrd-2.0.1\n"
     ]
    }
   ],
   "source": [
    "!pip install xlrd   # 安装支持xls的脚本"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "e74a427e-1882-48ab-aed2-d4c558c0b14a",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "data = pd.read_excel(r\"data/KeyDevelopment Screening Report.xls\",header=7).sample(20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "4094391b-3d79-49a3-87dc-25cefedfe1ca",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "No engine for filetype: 'xls'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mOptionError\u001b[0m                               Traceback (most recent call last)",
      "File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\pandas\\io\\excel\\_base.py:1153\u001b[0m, in \u001b[0;36mExcelWriter.__new__\u001b[1;34m(cls, path, engine, date_format, datetime_format, mode, storage_options, if_sheet_exists, engine_kwargs)\u001b[0m\n\u001b[0;32m   1152\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m-> 1153\u001b[0m     engine \u001b[38;5;241m=\u001b[39m config\u001b[38;5;241m.\u001b[39mget_option(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mio.excel.\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mext\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m.writer\u001b[39m\u001b[38;5;124m\"\u001b[39m, silent\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[0;32m   1154\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m engine \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mauto\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n",
      "File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\pandas\\_config\\config.py:272\u001b[0m, in \u001b[0;36mCallableDynamicDoc.__call__\u001b[1;34m(self, *args, **kwds)\u001b[0m\n\u001b[0;32m    271\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__call__\u001b[39m(\u001b[38;5;28mself\u001b[39m, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwds) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m T:\n\u001b[1;32m--> 272\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__func__\u001b[39m(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwds)\n",
      "File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\pandas\\_config\\config.py:146\u001b[0m, in \u001b[0;36m_get_option\u001b[1;34m(pat, silent)\u001b[0m\n\u001b[0;32m    145\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_get_option\u001b[39m(pat: \u001b[38;5;28mstr\u001b[39m, silent: \u001b[38;5;28mbool\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mFalse\u001b[39;00m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Any:\n\u001b[1;32m--> 146\u001b[0m     key \u001b[38;5;241m=\u001b[39m _get_single_key(pat, silent)\n\u001b[0;32m    148\u001b[0m     \u001b[38;5;66;03m# walk the nested dict\u001b[39;00m\n",
      "File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\pandas\\_config\\config.py:132\u001b[0m, in \u001b[0;36m_get_single_key\u001b[1;34m(pat, silent)\u001b[0m\n\u001b[0;32m    131\u001b[0m         _warn_if_deprecated(pat)\n\u001b[1;32m--> 132\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m OptionError(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mNo such keys(s): \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mrepr\u001b[39m(pat)\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m    133\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(keys) \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m1\u001b[39m:\n",
      "\u001b[1;31mOptionError\u001b[0m: No such keys(s): 'io.excel.xls.writer'",
      "\nThe above exception was the direct cause of the following exception:\n",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[23], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m data\u001b[38;5;241m.\u001b[39mto_excel(\u001b[38;5;124mr\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdata.xls\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
      "File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\pandas\\core\\generic.py:2345\u001b[0m, in \u001b[0;36mNDFrame.to_excel\u001b[1;34m(self, excel_writer, sheet_name, na_rep, float_format, columns, header, index, index_label, startrow, startcol, engine, merge_cells, inf_rep, freeze_panes, storage_options, engine_kwargs)\u001b[0m\n\u001b[0;32m   2332\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpandas\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mio\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mformats\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mexcel\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m ExcelFormatter\n\u001b[0;32m   2334\u001b[0m formatter \u001b[38;5;241m=\u001b[39m ExcelFormatter(\n\u001b[0;32m   2335\u001b[0m     df,\n\u001b[0;32m   2336\u001b[0m     na_rep\u001b[38;5;241m=\u001b[39mna_rep,\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m   2343\u001b[0m     inf_rep\u001b[38;5;241m=\u001b[39minf_rep,\n\u001b[0;32m   2344\u001b[0m )\n\u001b[1;32m-> 2345\u001b[0m formatter\u001b[38;5;241m.\u001b[39mwrite(\n\u001b[0;32m   2346\u001b[0m     excel_writer,\n\u001b[0;32m   2347\u001b[0m     sheet_name\u001b[38;5;241m=\u001b[39msheet_name,\n\u001b[0;32m   2348\u001b[0m     startrow\u001b[38;5;241m=\u001b[39mstartrow,\n\u001b[0;32m   2349\u001b[0m     startcol\u001b[38;5;241m=\u001b[39mstartcol,\n\u001b[0;32m   2350\u001b[0m     freeze_panes\u001b[38;5;241m=\u001b[39mfreeze_panes,\n\u001b[0;32m   2351\u001b[0m     engine\u001b[38;5;241m=\u001b[39mengine,\n\u001b[0;32m   2352\u001b[0m     storage_options\u001b[38;5;241m=\u001b[39mstorage_options,\n\u001b[0;32m   2353\u001b[0m     engine_kwargs\u001b[38;5;241m=\u001b[39mengine_kwargs,\n\u001b[0;32m   2354\u001b[0m )\n",
      "File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\pandas\\io\\formats\\excel.py:946\u001b[0m, in \u001b[0;36mExcelFormatter.write\u001b[1;34m(self, writer, sheet_name, startrow, startcol, freeze_panes, engine, storage_options, engine_kwargs)\u001b[0m\n\u001b[0;32m    942\u001b[0m     need_save \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mFalse\u001b[39;00m\n\u001b[0;32m    943\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m    944\u001b[0m     \u001b[38;5;66;03m# error: Cannot instantiate abstract class 'ExcelWriter' with abstract\u001b[39;00m\n\u001b[0;32m    945\u001b[0m     \u001b[38;5;66;03m# attributes 'engine', 'save', 'supported_extensions' and 'write_cells'\u001b[39;00m\n\u001b[1;32m--> 946\u001b[0m     writer \u001b[38;5;241m=\u001b[39m ExcelWriter(  \u001b[38;5;66;03m# type: ignore[abstract]\u001b[39;00m\n\u001b[0;32m    947\u001b[0m         writer,\n\u001b[0;32m    948\u001b[0m         engine\u001b[38;5;241m=\u001b[39mengine,\n\u001b[0;32m    949\u001b[0m         storage_options\u001b[38;5;241m=\u001b[39mstorage_options,\n\u001b[0;32m    950\u001b[0m         engine_kwargs\u001b[38;5;241m=\u001b[39mengine_kwargs,\n\u001b[0;32m    951\u001b[0m     )\n\u001b[0;32m    952\u001b[0m     need_save \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[0;32m    954\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n",
      "File \u001b[1;32m~\\anaconda3\\Lib\\site-packages\\pandas\\io\\excel\\_base.py:1157\u001b[0m, in \u001b[0;36mExcelWriter.__new__\u001b[1;34m(cls, path, engine, date_format, datetime_format, mode, storage_options, if_sheet_exists, engine_kwargs)\u001b[0m\n\u001b[0;32m   1155\u001b[0m             engine \u001b[38;5;241m=\u001b[39m get_default_engine(ext, mode\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mwriter\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m   1156\u001b[0m     \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m err:\n\u001b[1;32m-> 1157\u001b[0m         \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mNo engine for filetype: \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mext\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01merr\u001b[39;00m\n\u001b[0;32m   1159\u001b[0m \u001b[38;5;66;03m# for mypy\u001b[39;00m\n\u001b[0;32m   1160\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m engine \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n",
      "\u001b[1;31mValueError\u001b[0m: No engine for filetype: 'xls'"
     ]
    }
   ],
   "source": [
    "不要运行\n",
    "data.to_excel(r\"data.xls\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "3df3f376-57b4-4a6d-a5f4-0e9268904a02",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting pyexcel-xls\n",
      "  Downloading pyexcel_xls-0.7.0-py2.py3-none-any.whl (11 kB)\n",
      "Collecting pyexcel-xlsx\n",
      "  Downloading pyexcel_xlsx-0.6.0-py2.py3-none-any.whl (9.6 kB)\n",
      "Collecting pyexcel-io>=0.6.2 (from pyexcel-xls)\n",
      "  Downloading pyexcel_io-0.6.6-py2.py3-none-any.whl (44 kB)\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     ---------------------------------------- 0.0/44.2 kB ? eta -:--:--\n",
      "     --------- ------------------------------ 10.2/44.2 kB ? eta -:--:--\n",
      "     --------- ------------------------------ 10.2/44.2 kB ? eta -:--:--\n",
      "     --------- ------------------------------ 10.2/44.2 kB ? eta -:--:--\n",
      "     --------- ------------------------------ 10.2/44.2 kB ? eta -:--:--\n",
      "     --------- ------------------------------ 10.2/44.2 kB ? eta -:--:--\n",
      "     --------- ------------------------------ 10.2/44.2 kB ? eta -:--:--\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     --------------------------- ----------- 30.7/44.2 kB 69.0 kB/s eta 0:00:01\n",
      "     ------------------------------------ -- 41.0/44.2 kB 19.5 kB/s eta 0:00:01\n",
      "     ------------------------------------ -- 41.0/44.2 kB 19.5 kB/s eta 0:00:01\n",
      "     ------------------------------------ -- 41.0/44.2 kB 19.5 kB/s eta 0:00:01\n",
      "     --------------------------------------- 44.2/44.2 kB 18.9 kB/s eta 0:00:00\n",
      "Requirement already satisfied: xlrd in c:\\users\\666\\anaconda3\\lib\\site-packages (from pyexcel-xls) (2.0.1)\n",
      "Requirement already satisfied: xlwt in c:\\users\\666\\anaconda3\\lib\\site-packages (from pyexcel-xls) (1.3.0)\n",
      "Requirement already satisfied: openpyxl>=2.6.1 in c:\\users\\666\\anaconda3\\lib\\site-packages (from pyexcel-xlsx) (3.0.10)\n",
      "Requirement already satisfied: et_xmlfile in c:\\users\\666\\anaconda3\\lib\\site-packages (from openpyxl>=2.6.1->pyexcel-xlsx) (1.1.0)\n",
      "Collecting lml>=0.0.4 (from pyexcel-io>=0.6.2->pyexcel-xls)\n",
      "  Downloading lml-0.1.0-py2.py3-none-any.whl (10 kB)\n",
      "Installing collected packages: lml, pyexcel-io, pyexcel-xlsx, pyexcel-xls\n",
      "Successfully installed lml-0.1.0 pyexcel-io-0.6.6 pyexcel-xls-0.7.0 pyexcel-xlsx-0.6.0\n"
     ]
    }
   ],
   "source": [
    "!pip install pyexcel-xls pyexcel-xlsx"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "d386cfff-8ee0-48a5-8242-f1a6c9bfec5c",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "data.to_excel(r\"out/data.xlsx\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "45984029-3c0b-4d23-8eb2-b64d5b831fa9",
   "metadata": {},
   "outputs": [],
   "source": [
    "data.to_csv(r\"out/data.csv\",index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ff4f5676-f855-43ba-b767-1ea0501c9328",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
